package com.atcx.service.impl;

import com.atcx.mapper.WarningMapper;
import com.atcx.pojo.Warning;
import com.atcx.service.WarningService;
import com.atcx.util.PageResult;
import com.atcx.util.QueryPageBean;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author pangShu
 * @since 2022-03-23
 */
@Service
public class WarningServiceImpl extends ServiceImpl<WarningMapper, Warning> implements WarningService {

    @Resource
    private WarningMapper warningMapper;
    @Override
    public int add(Warning warning) {
        int insert = warningMapper.insert(warning);
        return insert;
    }

    @Override
    public int updateWarning(Warning warning) {
        int i = warningMapper.updateById(warning);
        return i;
    }

    @Override
    public int delete(int id) {
        int i = warningMapper.deleteById(id);
        return i;
    }

    @Override
    public PageResult findByPage(QueryPageBean queryPageBean) {
        Page<Warning> page = new Page<>(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        QueryWrapper<Warning> wrapper = new QueryWrapper<>();
        if (queryPageBean.getQueryString()!= null&&queryPageBean.getQueryString().trim().length()!=0){
            //有查询条件就添加查询条件
            String trim = queryPageBean.getQueryString().trim();
            wrapper.eq("name",trim);
        }
        Page<Warning> warningPage = warningMapper.selectPage(page, wrapper);
        PageResult pageResult = new PageResult(warningPage.getTotal(), warningPage.getRecords());
        return pageResult;
    }
}
